package com.hmall.search.mq;

import com.hmall.search.constant.MqConstant;
import com.hmall.search.service.ISearchService;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * 监听类
 */
@Component
public class SearchListener {

    @Autowired
    private ISearchService searchService;

    /**
     * 监听商品新增或修改的业务
     *
     * @param id 商品id
     */
    @RabbitListener(queues = MqConstant.HMALL_INSERT_QUEUE)
    public void listenInsertUpdate(Long id) throws IOException {
        searchService.insertById(id);
    }

    /**
     * 监听商品删除的业务
     * @param id 商品id
     */
    @RabbitListener(queues = MqConstant.HMALL_DELETE_QUEUE)
    public void listenDelete(Long id) throws IOException {
        searchService.deleteById(id);
    }

}
